package com.scvtc.controller.student;

import com.scvtc.domain.ResResult;
import com.scvtc.domain.dto.student.base.StudentsBaseDto;
import com.scvtc.domain.vo.PageVo;
import com.scvtc.domain.vo.student.base.StuEnrollmentPlanVo;
import com.scvtc.service.student.StudentsBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.Digits;
import java.util.List;
import java.util.Map;

import static com.scvtc.constants.SystemCheckedConstants.PAGE_CURRENT_ERROR;
import static com.scvtc.constants.SystemCheckedConstants.PAGE_SIZE_ERROR;
import static com.scvtc.constants.SystemConstants.PAGE_CURRENT;
import static com.scvtc.constants.SystemConstants.PAGE_SIZE;

/**
 * 学生基本信息(StudentsBase)表控制层
 *
 * @author yiFei
 * @since 2022-04-13 17:38:27
 */
@Api(tags = "学生基本信息(StudentsBase)")
@RestController
@RequestMapping("studentsBase")
public class StudentsBaseController {
    /**
     * 学生基本信息(StudentsBase)对象
     */
    @Autowired
    private StudentsBaseService studentsBaseService;

    @GetMapping("/list")
    @ApiOperation("查询学生信息")
    @PreAuthorize("hasAuthority('student:base:list')")
    public ResResult<PageVo<List<StudentsBaseDto>>> getAllStudentBase(
            @Digits(integer = 5, fraction = 1, message = PAGE_CURRENT_ERROR) @RequestParam(defaultValue = PAGE_CURRENT) Long current,
            @Digits(integer = 3, fraction = 0, message = PAGE_SIZE_ERROR) @RequestParam(defaultValue = PAGE_SIZE) Long size,
            StudentsBaseDto studentsBaseDto
    ) {
        return studentsBaseService.getAllStudentBase(current, size, studentsBaseDto);
    }

    @PostMapping("/")
    @ApiOperation("添加单个学生")
    @PreAuthorize("hasAuthority('student:base:add')")
    public ResResult<?> addStudentBase(@RequestBody StudentsBaseDto studentsBaseDto) {
        return studentsBaseService.addStudentBase(studentsBaseDto);
    }

    @PutMapping("/")
    @ApiOperation("修改单个学生")
    @PreAuthorize("hasAuthority('student:base:update')")
    public ResResult<?> updateStudentBase(@RequestBody StudentsBaseDto studentsBaseDto) {
        return studentsBaseService.updateStudentBase(studentsBaseDto);
    }

    @DeleteMapping("/")
    @ApiOperation("删除单个学生")
    @PreAuthorize("hasAuthority('student:base:delete')")
    public ResResult<?> deleteStudentBase(Long id) {
        return studentsBaseService.deleteStudentBase(id);
    }

    @DeleteMapping("/multiple")
    @ApiOperation("删除多个学生")
    @PreAuthorize("hasAuthority('student:base:delete')")
    public ResResult<?> deleteMultipleStudentBase(Long[] ids) {
        return studentsBaseService.deleteMultipleStudentBase(ids);
    }

//    @GetMapping(value = "/export", produces = "application/octet-stream")
//    @ApiOperation("导出excel")
//    @PreAuthorize("hasAuthority('student:base:list')")
//    public void exportExcel(
//            HttpServletResponse response,
//            StudentsBaseDto studentsBaseDto
//    ) {
//        studentsBaseService.exportExcel(response, studentsBaseDto);
//    }

    @GetMapping(value = "/export", produces = "application/octet-stream")
    @ApiOperation("导出excel")
    @PreAuthorize("hasAuthority('student:base:list')")
    public void exportExcel(
            HttpServletResponse response,
            Long[] ids
    ) {
        studentsBaseService.exportExcel(response,ids);

    }
    @GetMapping(value = "/chart/gender")
    @ApiOperation("学生男女比例")
    public ResResult<List<Map<String, Object>>> chartGender() {
        return studentsBaseService.chartGender();
    }

    @GetMapping(value = "/chart/enrollment")
    @ApiOperation("学生近三年招生")
    public ResResult<List<StuEnrollmentPlanVo>> chartEnrollmentPlan() {
        return studentsBaseService.chartEnrollmentPlan();
    }
}

